﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.OutBound.WizardAgent
{
    /// <summary>
    /// 车辆功能特征（比如：自动挡、4座等）
    /// </summary>
    public class CarFeatureDto
    {
        /*
         * Wizard接口返回的数据如下：
         * <Reference Type="Features" ID="Smoke Free|4 Door|Seats 7|AM/FM Radio|CD Player|Air Bags|Air Conditioning|Power Steering|Power Locks|Power Windows|Anti-Lock Brakes|Cruise Control|Tilt Steering Wheel|Automatic|Holds 1 large, 1 small Suitcases|14-19 mpg|image=2016-chevrolet-tahoe-lt-suv-black.png|thumb=2016-chevrolet-tahoe-lt-suv-black.png|cargroup=Z|category=Full Size SUV"/>
         * Smoke Free：      无烟
         * 2 or 4 Doors：    2门或4门
         * Seats 5：         5座
         * AM/FM Radio：     调幅/调频收音机
         * Air Bags：        空气袋
         * Air Conditioning：空调
         * Power Steering：  动力转向
         * Power Brakes：    动力制动
         * Power Windows：   电动车窗
         * Automatic：       自动挡
         * Holds 1 large, 2 small Suitcases：可容纳一个大的，两个小的行李箱
         * 28-48 mpg:
         * image=2016-ford-focus-se-sedan-side-view-race-red.png:
         * thumb=2016-ford-focus-se-sedan-side-view-race-red.png:
         * cargroup=B:
         * category=Compact：类型=紧凑
         */
        public CarFeatureDto(string features)
        {
            if (string.IsNullOrWhiteSpace(features))
                return;

            this.FeaturesString = features;
            var items = features.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            //this.IsAutomatic = items.Contains("Automatic");
            this.HasAirConditioning = items.Contains("Air Conditioning"); ;

            if (items.Contains("Automatic", StringComparer.OrdinalIgnoreCase))
            {
                this.IsAutomatic = true;
            }
            else if (items.Contains("Manual", StringComparer.OrdinalIgnoreCase))
            {
                this.IsAutomatic = false;
            }
            else
            {
                this.IsAutomatic = null;
            }


            var strDoors = items.FirstOrDefault(key => key.ToLower().Contains("Door".ToLower()) || key.ToLower().Contains("Doors".ToLower()));
            if (!string.IsNullOrWhiteSpace(strDoors))
            {
                this.Doors = strDoors;
            }

            var strSeats = items.FirstOrDefault(key => key.ToLower().Contains("Seats".ToLower()));
            if (!string.IsNullOrWhiteSpace(strSeats))
            {
                this.Seats = strSeats;
            }

            var strSuitcases = items.FirstOrDefault(key => key.ToLower().Contains("Suitcases".ToLower()));
            if (!string.IsNullOrWhiteSpace(strSuitcases))
            {
                this.Suitcases = strSuitcases;
            }

            var strCategory = items.FirstOrDefault(key => key.ToLower().Contains("category".ToLower()));
            if (!string.IsNullOrWhiteSpace(strCategory))
            {
                this.Category = strCategory.Replace("category=", "");
            }
        }

        /// <summary>
        /// 车辆有几门（如：2门、4门等）
        /// </summary>
        public string Doors { get; set; }

        /// <summary>
        /// 车辆有几座（如：2座、4座等）
        /// </summary>
        public string Seats { get; set; }

        /// <summary>
        /// 是否为自动挡
        /// </summary>
        public bool? IsAutomatic { get; set; }

        /// <summary>
        /// 是否有空调
        /// </summary>
        public bool? HasAirConditioning { get; set; }

        /// <summary>
        /// 可容纳多少件行李箱（如：Holds 2 small Suitcases）
        /// </summary>
        public string Suitcases { get; set; }

        /// <summary>
        /// 车辆类型：如紧凑、宽敞等
        /// </summary>
        public string Category { get; set; }

        /// <summary>
        /// 功能特征的描述信息
        /// </summary>
        public string FeaturesString { get; set; }

    }
}
